﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebShopData;

namespace Projekt_2_ASP.NET
{
   
    public partial class Contact : Page
    {
         private Order _order;
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Title = "Kundvagn";
            _order = (Order)Session["Order"];

            var orderRows = _order.OrderRows;

            int[] identifiers = _order.OrderRows.Select(x => x.ArticleID).ToArray();
            Article[] articles = WebShopDal.ReadArticles(identifiers);
            List<string> names = articles.Select(x => x.Name).ToList();

            List<dynamic> list = new List<dynamic>();
            for (int i = 0; i < orderRows.Count; i++)
            {
                list.Add(new { Text = names[i], Quantity = orderRows[i].Quantity });
            }

            GridView1.DataSource = list;
            GridView1.DataBind();
        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            (Session["Order"] as Order).OrderRows.RemoveAt(e.RowIndex);
            Response.Redirect("Cart.aspx");
        }
    }
}